package com.haoze.nurseapp.enumeration;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author embed
 */
public class QrScreenTypeEnum {
    private String enumValue;
    private String enumName;
    public final static Map<String, QrScreenTypeEnum> ENUM_MAP = new HashMap();

    /**
     * 工作台扫码入口
     */
    public final static QrScreenTypeEnum WORK_SPACE_QRSCREEN = new QrScreenTypeEnum("0", "工作台扫码");
    /**
     * 通用二维码扫码入口
     */
    public final static QrScreenTypeEnum COMMON_QRSCREEN = new QrScreenTypeEnum("1", "通用扫码");

    private QrScreenTypeEnum(String enumValue, String enumName){
        this.enumValue = enumValue;
        this.enumName = enumName;
    }

    public static QrScreenTypeEnum fromValue(String enumValue){
        putSourceEnum();
        return ENUM_MAP.get(enumValue);
    }

    public static void putSourceEnum(){

        Class clazz = QrScreenTypeEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        QrScreenTypeEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    field.setAccessible(true);
                    enumClass = (QrScreenTypeEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    ENUM_MAP.put(enumClass.getEnumValue(),enumClass);
                }
            }
        }
    }

    public String getEnumValue() {
        return enumValue;
    }

    public String getEnumName() {
        return enumName;
    }

}
